package com.henzil.siji.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.henzil.siji.bean.Weather;

public class DataUtil {

	
	public static Weather getAllWeatherInfo(Weather oldWeather){
		Weather newWeather = oldWeather;
		
		newWeather.getForecast_conditionses().get(0).setDay(getTodayDate());
		newWeather.getForecast_conditionses().get(1).setDay(getTomorrowDate());
		newWeather.getForecast_conditionses().get(2).setDay(getAcquiredDate());
		
		return newWeather;
		
	}
	
	public static Drawable setWeartherDrawable(Context context, String icon){
		Drawable drawable = null;
		if(icon.equals("/ig/images/weather/sunny.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.sunny);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/mostly_sunny.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.mostly_sunny);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/cn_heavyrain.gif") || icon.equals("/ig/images/weather/cn_lightrain.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.rain);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/partly_cloudy.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.partly_cloudy);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/cn_showers.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.chance_of_rain);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/storm.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.storm);
			return drawable;
		}
		if(icon.equals("/ig/images/weather/snow.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.snow);
			return drawable;
		}
		if(icon.equals("ig/images/weather/mostly_cloudy.gif")){
			drawable = context.getResources().getDrawable(com.henzil.siji.R.drawable.mostly_cloudy);
			return drawable;
		}
		
		return context.getResources().getDrawable(com.henzil.siji.R.drawable.weather_icon_1);
	}
	
	private static String getTodayDate(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("M月d日");
		Date date = new Date();
		return dateFormat.format(date);
	}
	
	private static String getTomorrowDate(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("M月d日");
		Date d = new Date(); 
        Calendar now = Calendar.getInstance(); 
        now.setTime(d); 
        now.set(Calendar.DATE, now.get(Calendar.DATE) + 1); 
		return dateFormat.format(now.getTime());
	}

	private static String getAcquiredDate(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("M月d日");
		Date d = new Date(); 
        Calendar now = Calendar.getInstance(); 
        now.setTime(d); 
        now.set(Calendar.DATE, now.get(Calendar.DATE) + 2); 
		return dateFormat.format(now.getTime());
	}
}
